package com.ruoyi.system.service.impl;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.system.domain.xcx.AppUser;
import com.ruoyi.system.domain.xcx.Goods;
import com.ruoyi.system.mapper.GoodsMapper;
import com.ruoyi.system.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * 商品管理Service业务层处理
 *
 * @author ruoyi
 * @date 2023-09-30
 */
@Service
public class GoodsServiceImpl implements IGoodsService
{
    @Autowired
    private GoodsMapper goodsMapper;

    @Autowired
    private RedisCache redisCache;
    /**
     * 项目启动时，初始化字典到缓存
     */
    @PostConstruct
    public void init()
    {
        loadingGoodSCache();
    }

    /**
     * 加载字典缓存数据
     */
    public void loadingGoodSCache()
    {
        List<Goods> list=goodsMapper.selectGoodsList(new Goods());
        for (Goods goods : list) {
            Goods goodsCache=new Goods();
            goodsCache.setGoodId(goods.getGoodId());
            goodsCache.setFirstPause(goods.getFirstPause());
            goodsCache.setSecondPause(goods.getSecondPause());
            goodsCache.setThirdPause(goods.getThirdPause());
            goodsCache.setGoodNum(goods.getGoodNum());
            goodsCache.setGoodsPrice(goods.getGoodsPrice());
            goodsCache.setBasicMemberPrice(goods.getBasicMemberPrice());
            goodsCache.setCpaBid(goods.getCpaBid());
            goodsCache.setStopType(goods.getStopType());
            goodsCache.setGoodSwitch(goods.getGoodSwitch());
            redisCache.setCacheObject(Constants.GOODS+goods.getGoodId(),goodsCache);
        }
    }
    /**
     * 查询商品管理
     *
     * @param goodId 商品管理主键
     * @return 商品管理
     */
    @Override
    public Goods selectGoodsByGoodId(String goodId)
    {
        return goodsMapper.selectGoodsByGoodId(goodId);
    }

    @Override
    public Goods selectGoodsByOrderNumber(Goods goods) {
        return goodsMapper.selectGoodsByOrderNumber(goods);
    }
    /**
     * 通过标题选择商品
     * @param goodTitle
     * @return
     */
    @Override
    public Goods selectGoodsByTitle(String goodTitle)
    {
        return goodsMapper.selectGoodsByTitle(goodTitle);
    }

    /**
     * 通过标题选择商品
     * @param goodTitle
     * @param merchantId
     * @return
     */
    @Override
    public Goods selectGoodsByTitleAndMerchantId(String goodTitle, String merchantId)
    {
        return goodsMapper.selectGoodsByTitleAndMerchantId(goodTitle, merchantId);
    }

    /**
     * 查询商品管理列表
     *
     * @param goods 商品管理
     * @return 商品管理
     */
    @Override
    public List<Goods> selectGoodsList(Goods goods)
    {
        return goodsMapper.selectGoodsList(goods);
    }

    /**
     * 新增商品管理
     *
     * @param goods 商品管理
     * @return 结果
     */
    @Override
    public int insertGoods(Goods goods)
    {
        return goodsMapper.insertGoods(goods);
    }

    /**
     * 修改商品管理
     *
     * @param goods 商品管理
     * @return 结果
     */
    @Override
    public int updateGoods(Goods goods)
    {
        return goodsMapper.updateGoods(goods);
    }

    /**
     * 批量删除商品管理
     *
     * @param goodIds 需要删除的商品管理主键
     * @return 结果
     */
    @Override
    public int deleteGoodsByGoodIds(String[] goodIds)
    {
        return goodsMapper.deleteGoodsByGoodIds(goodIds);
    }

    /**
     * 删除商品管理信息
     *
     * @param goodId 商品管理主键
     * @return 结果
     */
    @Override
    public int deleteGoodsByGoodId(String goodId)
    {
        return goodsMapper.deleteGoodsByGoodId(goodId);
    }

    @Override
    public List<Goods> selectGoodsByGoodIds(String[] goodIds) {
        return this.goodsMapper.selectGoodsByGoodIds(goodIds);
    }

    @Override
    public List<Goods> selectGoodsListByUser(Goods goods) {
        return goodsMapper.selectGoodsListByUser(goods);
    }

    @Override
    public Goods selectGoodsInfo(Goods good) {
        return null;
    }

}
